package core.imust.com.jrtt;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.VideoView;


public class SplahActivity extends AppCompatActivity {
    private boolean isClickClose = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splah);
//        1.复制一个视频到res/raw文件夹
//        2.视频路径
        String mp4 = "android.resource://"+getPackageName()+"/"+R.raw.video ;
        Uri uri = Uri.parse(mp4);
//      3.先在layout布局文件中配置一个 VideoView再找出来


        VideoView videoView = (VideoView) findViewById(R.id.video_view);

        setFullWidth(videoView);

        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {
                isClickClose = true;
                Intent intent = new Intent(  SplahActivity.this,MainActivity.class);
                startActivity(intent);
                finish();

            }
        });

        videoView.setVideoURI(uri);
//        执行播放方法
        videoView.start();

        findViewById(R.id.btn_jump).setOnClickListener(new View.OnClickListener(){
            @Override
           public void onClick(View view){
                if (isClickClose){
//                  什么都不做
                }else{
                    Intent intent = new Intent(  SplahActivity.this,MainActivity.class);
                    startActivity(intent);
                    finish();
                }

        }

        });

    }

    public void setFullWidth(VideoView videoView){
        DisplayMetrics metrics= getResources().getDisplayMetrics();
        int width = metrics.widthPixels;
        int heigh = metrics.heightPixels;
        RelativeLayout.LayoutParams params= new RelativeLayout.LayoutParams(width,heigh);
        videoView.setLayoutParams(params);

    }

}
